package o;

import android.text.TextUtils;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public class dnz extends dns {
    private int ʻ;
    private float ʼ;
    private String ˏॱ;
    private String ॱॱ;
    private List<dnq> ᐝ;

    class d implements e {
        private int ˋ;
        final /* synthetic */ dnz ˏ;

        public d(dnz o_dnz, int i) {
            this.ˏ = o_dnz;
            this.ˋ = i;
        }

        protected void ˋ() {
            String str;
            Exception e;
            dnq o_dnq;
            String str2 = "";
            String str3 = "";
            try {
                str = String.format(Locale.ENGLISH, "ping -c 1 -t %d ", new Object[]{Integer.valueOf(this.ˏ.ʻ)}) + this.ˏ.ˊ;
                try {
                    str2 = new dny(this).ˏ(str).ˋ();
                } catch (Exception e2) {
                    e = e2;
                    Logger.ˋ(this.ˏ.ˎ, "excute Exception = " + e.toString());
                    if (str2.contains("100%")) {
                    }
                    o_dnq = new dnq(str, str2, ˎ(str2), this.ˏ.ʻ == this.ˋ ? Float.parseFloat(ˊ(str2)) : this.ˏ.ʼ);
                    o_dnq.ˏ(InetAddress.getByName(this.ˏ.ˊ).getHostAddress());
                    this.ˏ.ᐝ.add(o_dnq);
                    if (!TextUtils.isEmpty(str2)) {
                        if (((dnq) this.ˏ.ᐝ.get(this.ˏ.ᐝ.size() - 1)).ˊ().equals(this.ˏ.ॱॱ)) {
                            if (this.ˏ.ʻ < this.ˋ) {
                                this.ˏ.ʻ = this.ˋ;
                                this.ˏ.ᐝ.remove(this.ˏ.ᐝ.size() - 1);
                                new d(this.ˏ, this.ˋ).ˋ();
                                return;
                            }
                            this.ˏ.ˊ(this.ˏ.ᐝ);
                        } else if (this.ˏ.ʻ < this.ˋ) {
                            this.ˏ.ʻ = this.ˏ.ʻ + 1;
                            new d(this.ˏ, this.ˋ).ˋ();
                        } else {
                            this.ˏ.ˊ(this.ˏ.ᐝ);
                        }
                    }
                }
            } catch (Exception e3) {
                Exception exception = e3;
                str = str3;
                e = exception;
                Logger.ˋ(this.ˏ.ˎ, "excute Exception = " + e.toString());
                if (str2.contains("100%")) {
                }
                if (this.ˏ.ʻ == this.ˋ) {
                }
                o_dnq = new dnq(str, str2, ˎ(str2), this.ˏ.ʻ == this.ˋ ? Float.parseFloat(ˊ(str2)) : this.ˏ.ʼ);
                o_dnq.ˏ(InetAddress.getByName(this.ˏ.ˊ).getHostAddress());
                this.ˏ.ᐝ.add(o_dnq);
                if (!TextUtils.isEmpty(str2)) {
                }
                if (((dnq) this.ˏ.ᐝ.get(this.ˏ.ᐝ.size() - 1)).ˊ().equals(this.ˏ.ॱॱ)) {
                    if (this.ˏ.ʻ < this.ˋ) {
                        this.ˏ.ˊ(this.ˏ.ᐝ);
                    }
                    this.ˏ.ʻ = this.ˏ.ʻ + 1;
                    new d(this.ˏ, this.ˋ).ˋ();
                } else if (this.ˏ.ʻ < this.ˋ) {
                    this.ˏ.ˊ(this.ˏ.ᐝ);
                } else {
                    this.ˏ.ʻ = this.ˋ;
                    this.ˏ.ᐝ.remove(this.ˏ.ᐝ.size() - 1);
                    new d(this.ˏ, this.ˋ).ˋ();
                    return;
                }
            }
            if (str2.contains("100%") || str2.contains("exceed")) {
                if (this.ˏ.ʻ == this.ˋ) {
                }
                o_dnq = new dnq(str, str2, ˎ(str2), this.ˏ.ʻ == this.ˋ ? Float.parseFloat(ˊ(str2)) : this.ˏ.ʼ);
            } else {
                o_dnq = new dnq(str, str2, ˎ(str2), this.ˏ.ʼ);
            }
            try {
                o_dnq.ˏ(InetAddress.getByName(this.ˏ.ˊ).getHostAddress());
            } catch (UnknownHostException e4) {
                Logger.ˋ(this.ˏ.ˎ, "excute UnknownHostException = " + e4.toString());
            }
            this.ˏ.ᐝ.add(o_dnq);
            if (!TextUtils.isEmpty(str2)) {
                if (((dnq) this.ˏ.ᐝ.get(this.ˏ.ᐝ.size() - 1)).ˊ().equals(this.ˏ.ॱॱ)) {
                    if (this.ˏ.ʻ < this.ˋ) {
                        this.ˏ.ʻ = this.ˋ;
                        this.ˏ.ᐝ.remove(this.ˏ.ᐝ.size() - 1);
                        new d(this.ˏ, this.ˋ).ˋ();
                        return;
                    }
                    this.ˏ.ˊ(this.ˏ.ᐝ);
                } else if (this.ˏ.ʻ < this.ˋ) {
                    this.ˏ.ʻ = this.ˏ.ʻ + 1;
                    new d(this.ˏ, this.ˋ).ˋ();
                } else {
                    this.ˏ.ˊ(this.ˏ.ᐝ);
                }
            }
        }

        private String ˎ(String str) {
            String str2 = "";
            try {
                if (str.contains("From")) {
                    str2 = str.substring(str.indexOf("From") + 5);
                    if (str2.contains("(")) {
                        return str2.substring(str2.indexOf("(") + 1, str2.indexOf(")"));
                    }
                    int indexOf;
                    str2 = str2.substring(0, str2.indexOf("\n"));
                    if (str2.contains(":")) {
                        indexOf = str2.indexOf(":");
                    } else {
                        indexOf = str2.indexOf(HwAccountConstants.BLANK);
                    }
                    return str2.substring(0, indexOf);
                }
                return str.substring(str.indexOf("(") + 1, str.indexOf(")"));
            } catch (StringIndexOutOfBoundsException e) {
                StringIndexOutOfBoundsException stringIndexOutOfBoundsException = e;
                String str3 = str2;
                Logger.ˋ(this.ˏ.ˎ, "parseIpFromPing StringIndexOutOfBoundsException=" + stringIndexOutOfBoundsException.toString());
                return str3;
            }
        }

        private String ॱ(String str) {
            String str2 = "";
            if (!str.contains("PING")) {
                return str2;
            }
            return str.substring(str.indexOf("(") + 1, str.indexOf(")"));
        }

        private String ˊ(String str) {
            String str2 = "";
            if (!str.contains("time=")) {
                return str2;
            }
            str2 = str.substring(str.indexOf("time=") + 5);
            return str2.substring(0, str2.indexOf(HwAccountConstants.BLANK));
        }

        public void ॱ(String str, long j) {
            if (str.contains("From") || str.contains("from")) {
                this.ˏ.ʼ = ((float) (System.nanoTime() - j)) / 1000000.0f;
            }
        }

        public void ˏ(String str) {
            if (this.ˏ.ʻ == 1) {
                this.ˏ.ॱॱ = ॱ(str);
            }
        }
    }

    public dnz() {
        this.ʻ = 1;
        this.ᐝ = new ArrayList();
        this.ˏॱ = "";
        this.ˎ = "TraceDiagnoseLogger";
    }

    public String ˊ() {
        new d(this, 30).ˋ();
        return this.ˏॱ;
    }

    private void ˊ(List<dnq> list) {
        int size = list.size();
        Logger.ˎ(this.ˎ, "showResultInLog traces size=" + size);
        StringBuilder stringBuilder = new StringBuilder();
        int i = 0;
        for (dnq o_dnq : list) {
            i++;
            stringBuilder.append(o_dnq.ˋ()).append("\n").append(o_dnq.ॱ());
            if (i < size) {
                stringBuilder.append("\n");
            }
        }
        this.ˏॱ = stringBuilder.toString();
    }
}
